package com.jbm.jbmsupplier.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TabWidget;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.view.AnimationTabHost;
import com.jbm.jbmsupplier.zp.liaotian.Recent_ContactsActivity;
import com.jbm.jbmsupplier.zp.liaotian.TestDuiHuaActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 家帮忙 on 2017/4/10.
 */

public class MainActivity extends TabActivity implements RadioGroup.OnCheckedChangeListener {
    @InjectView(android.R.id.tabcontent)
    FrameLayout tabcontent;
    @InjectView(android.R.id.tabs)
    TabWidget tabs;
    static RadioButton radioButton1;
    static AnimationTabHost tabhost;
    @InjectView(R.id.radioButton2)
    RadioButton radioButton2;
    @InjectView(R.id.radioButton5)
    RadioButton radioButton5;
    @InjectView(R.id.group)
    RadioGroup group;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        ButterKnife.inject(this);
        tabhost = (AnimationTabHost) findViewById(android.R.id.tabhost);
        radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
        setGainTab();
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.radioButton1:
                tabhost.setCurrentTabByTag("NEWHOME");
                break;
            case R.id.radioButton2:
                tabhost.setCurrentTabByTag("MESSAGEINFORM");
                break;
            case R.id.radioButton5:
                tabhost.setCurrentTabByTag("MYFRIEND");

                break;
        }
    }

    public void setGainTab() {
        tabhost.setOpenAnimation(true);
        //获取TabHost组件
        TabHost tabhosts = getTabHost();
        //创建一个标签
        TabHost.TabSpec tabspec = tabhosts.newTabSpec("NEWHOME").setIndicator("NEWHOME");
        //需要跳转的页面
        tabspec.setContent(new Intent(MainActivity.this, NewHomeActivity.class));
        //把tabhost添加到标签中
        tabhost.addTab(tabspec);
        TabHost.TabSpec tabspec3 = tabhosts.newTabSpec("MESSAGEINFORM").setIndicator("MESSAGEINFORM");
        tabspec3.setContent(new Intent(MainActivity.this, Recent_ContactsActivity.class));
        tabhost.addTab(tabspec3);
        TabHost.TabSpec tabspec4 = tabhosts.newTabSpec("MYFRIEND").setIndicator("MYFRIEND");
        tabspec4.setContent(new Intent(MainActivity.this, TestDuiHuaActivity.class));
        tabhost.addTab(tabspec4);
        group.setOnCheckedChangeListener(this);
        if(getIntent().getStringExtra("main")==null)
        {
            tabhost.setCurrentTabByTag("MESSAGEINFORM");
            radioButton2.setChecked(true);
        }else
         if (getIntent().getStringExtra("main").equals("")){
       }else
        if (getIntent().getStringExtra("main").equals("1")){
            tabhost.setCurrentTabByTag("MESSAGEINFORM");
            radioButton2.setChecked(true);
}
    }

    public static void setNewHome() {
        tabhost.setCurrentTabByTag("NEWHOME");
        radioButton1.setChecked(true);
    }


    @OnClick({R.id.radioButton1, R.id.radioButton2, R.id.radioButton5, R.id.group, android.R.id.tabhost})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.radioButton1:
                break;
            case R.id.radioButton2:
                break;
            case R.id.radioButton5:
                break;
            case R.id.group:
                break;
            case android.R.id.tabhost:
                break;
        }
    }
}
